home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / games / dissociate.el < prev    next >
Encoding:
Text File  |  1995-03-25  |  3.2 KB  |  103 lines

  1. ;;; dissociate.el --- scramble text amusingly for Emacs.
  2.  
  3. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6. ;; Keywords: games
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  22. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. ;;; Synched up with: FSF 19.28.
  25.  
  26. ;;; Commentary:
  27.  
  28. ;; The single entry point, `dissociated-press', applies a travesty
  29. ;; generator to the current buffer.  The results can be quite amusing.
  30.  
  31. ;;; Code:
  32.  
  33. ;;;###autoload
  34. (defun dissociated-press (&optional arg)
  35.   "Dissociate the text of the current buffer.
  36. Output goes in buffer named *Dissociation*,
  37. which is redisplayed each time text is added to it.
  38. Every so often the user must say whether to continue.
  39. If ARG is positive, require ARG chars of continuity.
  40. If ARG is negative, require -ARG words of continuity.
  41. Default is 2."
  42.   (interactive "P")
  43.   (setq arg (if arg (prefix-numeric-value arg) 2))
  44.   (let* ((inbuf (current-buffer))
  45.      (outbuf (get-buffer-create "*Dissociation*"))
  46.      (move-function (if (> arg 0) 'forward-char 'forward-word))
  47.      (move-amount (if (> arg 0) arg (- arg)))
  48.      (search-function (if (> arg 0) 'search-forward 'word-search-forward))
  49.      (last-query-point 0))
  50.     (if (= (point-max) (point-min))
  51.     (error "The buffer contains no text to start from"))
  52.     (switch-to-buffer outbuf)
  53.     (erase-buffer)
  54.     (while
  55.       (save-excursion
  56.     (goto-char last-query-point)
  57.     (vertical-motion (- (window-height) 4))
  58.     (or (= (point) (point-max))
  59.         (and (progn (goto-char (point-max))
  60.             (y-or-n-p "Continue dissociation? "))
  61.          (progn
  62.            (message "")
  63.            (recenter 1)
  64.            (setq last-query-point (point-max))
  65.            t))))
  66.       (let (start end)
  67.     (save-excursion
  68.      (set-buffer inbuf)
  69.      (setq start (point))
  70.      (if (eq move-function 'forward-char)
  71.          (progn
  72.            (setq end (+ start (+ move-amount (random 16))))
  73.            (if (> end (point-max))
  74.            (setq end (+ 1 move-amount (random 16))))
  75.            (goto-char end))
  76.        (funcall move-function
  77.             (+ move-amount (random 16))))
  78.      (setq end (point)))
  79.     (let ((opoint (point)))
  80.       (insert-buffer-substring inbuf start end)
  81.       (save-excursion
  82.        (goto-char opoint)
  83.        (end-of-line)
  84.        (and (> (current-column) fill-column)
  85.         (do-auto-fill)))))
  86.       (save-excursion
  87.        (set-buffer inbuf)
  88.        (if (eobp)
  89.        (goto-char (point-min))
  90.      (let ((overlap
  91.         (buffer-substring (prog1 (point)
  92.                      (funcall move-function
  93.                           (- move-amount)))
  94.                   (point))))
  95.        (goto-char (1+ (random (1- (point-max)))))
  96.        (or (funcall search-function overlap nil t)
  97.            (let ((opoint (point)))
  98.          (goto-char 1)
  99.          (funcall search-function overlap opoint t))))))
  100.       (sit-for 0))))
  101.  
  102. ;;; dissociate.el ends here
  103.